package com.haiertvbic.tvnow.protocol;

public class ConnectManager {
	// APP 获取地域信息码
	public static final int CMD_CAE_APP_GET_LOCAL_CODE = 40062;
	public static final int CMD_CAE_APP_GET_LOCAL_CODE_RE = 40063;

	// UI 请求CAE 获取收视率排前的频道信息
	public static final int CMD_CAE_APP_GET_AUDIO_RATE = 40060;
	public static final int CMD_CAE_APP_GET_AUDIO_RATE_RE = 40061;

	// PAD/Phone 智能终端控制CAE 切台
	public static final int CMD_SENT_CHANNEL_INFO = 40044;
	public static final int CMD_SENT_CHANNEL_INFO_RE = 40045;

	// 向cae请求信号源
	public static final int CMD_VD_REQ_CURRENT_SIG_SOURCE = 40016;
	public static final int CMD_VD_REQ_CURRENT_SIG_SOURCE_RE = 40017;

	// 通过全国id向CAE请求dtv的id
	public static final int CMD_SMART_TV_ASK_LOCAL_ID_BY_COUNTRY_ID = 40084;
	public static final int CMD_SMART_TV_ASK_LOCAL_ID_BY_COUNTRY_ID_RE = 40085;

	// CAE 查询UI 频道改变
	public static final int CMD_CAE_APP_GET_TV_ID = 40048;
	public static final int CMD_CAE_APP_GET_TV_ID_RE = 40049;

	// CAE连接端口及服务
	public static final String LOCAL_HOST = "127.0.0.1";
	// public static final String LOCAL_HOST = "192.168.200.55";
	public static final int SERVICE_HOST_PORT = 7888;// 询问信号源端口
	public static final int CHANNEL_PORT = 7204; // 得到频道列表的端口

	public static final byte[] intToByte(int i) {
		byte[] abyte0 = new byte[4];
		abyte0[3] = (byte) (0xff & i);
		abyte0[2] = (byte) ((0xff00 & i) >> 8);
		abyte0[1] = (byte) ((0xff0000 & i) >> 16);
		abyte0[0] = (byte) ((0xff000000 & i) >> 24);
		return abyte0;
	}

	public static short bytesToShort(byte[] bytesShort) {
		short sRet = 0;
		sRet += (bytesShort[0] & 0xFF) << 8;
		sRet += bytesShort[1] & 0xFF;
		return sRet;
	}

	/**
	 * short到字节数组的转换
	 * 
	 * @param s
	 * @return
	 */
	public static byte[] shortToByte(short number) {
		int temp = number;
		byte[] b = new byte[2];
		for (int i = b.length - 1; i >= 0; i--) {
			b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位
			temp = temp >> 8; // 向右移8位
		}
		return b;
	}
}
